﻿using System;
using System.Threading;

namespace ServiceTesting
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var client = new CommSrv.YouTubeDownloaderCommSrvClient())
            {
                var urls = new[] {
                                    "http://www.youtube.com/watch?v=Lsx5CiK1Z2s",
                                    "http://www.youtube.com/watch?v=ztC0QaS3_h4"
                };

                var result = client.GetFormats(urls[0]);
                if (result != null)
                {
                    Console.WriteLine("Title: " + result.Title);
                    foreach (var format in result.Formats)
                    {
                        Console.WriteLine(format.Code + " - " + format.Title);
                    }
                }

                var folders = client.GetSharedMediaFolders();
                foreach (var folder in folders)
                    Console.WriteLine(folder.Name + " - " + folder.FolderId);

                //foreach (var url in urls)
                //{
                //    client.DownloadFile(url, 18);
                //}

                CommSrv.DownloadItemStatus[] statuses;
                while ((statuses = client.GetItemStatuses()).Length > 0)
                    foreach (var status in statuses)
                    {
                        Console.Write(status.Title);
                        Console.Write(" ");
                        Console.Write(status.PercentDownloaded);
                        Console.WriteLine("%");

                        Thread.Sleep(3000);
                    }
            }
            Console.WriteLine("\r\nPress any key to exit");
            Console.ReadLine();
        }
    }
}
